package com.yy.wga.admin.service.controller;


import com.yy.wga.mp.common.interceptor.RequestUserHolder;
import com.yy.wga.mp.common.utils.mapping.BeansUtils;
import com.yy.wga.mp.module.admin.request.AdminResourceConfigPageRequest;
import com.yy.wga.mp.module.admin.request.AdminResourceConfigSaveRequest;
import com.yy.wga.mp.module.admin.response.AdminResourceConfigPageResponse;
import com.yy.wga.mp.module.resource.entity.pojo.ResourceConfigDO;
import com.yy.wga.mp.module.resource.service.ResourceConfigService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 运营后台/资源位配置
 *
 * @author guochao
 * @since 2024-10-31 22:12:53
 */
@RestController
@RequestMapping("admin/resource/config")
public class AdminResourceConfigController {
    /**
     * 服务对象
     */
    @Resource
    private ResourceConfigService resourceConfigService;

    @PostMapping("page")
    public Result<PageBean<AdminResourceConfigPageResponse>> page(@Valid @RequestBody AdminResourceConfigPageRequest request) {
        PageBean<AdminResourceConfigPageResponse> pageBean = resourceConfigService.pageData(request);
        return Result.success(pageBean);
    }

    @PostMapping("save")
    public Result<Boolean> save(@Valid @RequestBody AdminResourceConfigSaveRequest request) {
        ResourceConfigDO config = BeansUtils.map(request, ResourceConfigDO.class);
        config.setAppKey(RequestUserHolder.getBaseRequest().getAppKey());
        resourceConfigService.saveOrUpdate(config);
        return Result.success(Boolean.TRUE);
    }

    @GetMapping("del")
    public Result<Boolean> del(@RequestParam("id") Long id) {
        resourceConfigService.removeById(id);
        return Result.success(Boolean.TRUE);
    }
}
